package com.nativetalk.controller.app.three.study;

import com.nativetalk.base.Page;
import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.member.TdNtMember;
import com.nativetalk.common.Constants;
import com.nativetalk.common.util.JsonUtil;
import com.nativetalk.common.util.MemcachedUtils;
import com.nativetalk.service.three.study.search.ThreeStudySearchService;
import com.nativetalk.service.three.study.update.ThreeStudyUpdateService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by lizhun on 15/12/9.
 */
@Controller
public class ThreeStudyController {
     private static Logger logger = Logger.getLogger(ThreeStudyController.class);
     @Resource
     private ThreeStudyUpdateService threeStudyUpdateService;
     @Resource
     private ThreeStudySearchService threeStudySearchService;
    /**
     * @Purpose 预约呼叫 取消呼叫
     * @version  3.0
     * @time     2015-05-09
     * @author   lizhun
     * @return   RetInfo
     */
    @RequestMapping(value="/app/6/token/study/cancel" ,method = {RequestMethod.GET,RequestMethod.POST} ,consumes = "application/json" )
    @ResponseBody
    public RetInfo cancel(@RequestBody Map<String,Integer> map,
                          @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(map));

            TdNtMember tdNtMember = (TdNtMember) MemcachedUtils.get(token);
            RetInfo retInfo = threeStudyUpdateService.cancelOrders(map.get("stt_id"), tdNtMember);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }

    }
    /**
     * @Purpose  获取用户学习记录
     * @version  3.0
     * @time     2015-08-26
     * @author   lizhun
     * @return   RetInfo
     */
    @RequestMapping(value="/app/8/token/study/list" ,method = {RequestMethod.GET,RequestMethod.POST} ,consumes = "application/json" )
    @ResponseBody
    public RetInfo cancel(@RequestBody Page page,
                          @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(page));

            RetInfo retInfo;
            TdNtMember tdNtMember = (TdNtMember) MemcachedUtils.get(token);
            page.setObj(tdNtMember.getMemb_id());
            retInfo = threeStudySearchService.findStudyTeachPage(page);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }

    }
}


